<template>
<div class="task-logs">
    <div class="box-top">
        <el-form @submit.native.prevent>
            <el-form-item label="日志ID">
                <el-input clearable placeholder="请输入日志ID" v-model="form.logId"></el-input>
            </el-form-item>
            <el-form-item label="状态">
                <el-select clearable v-model="form.status" placeholder="请选择状态">
                    <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="计划执行时间">
                <el-date-picker v-model="form.excuteTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="开始时间">
                <el-date-picker v-model="form.startTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间">
                <el-date-picker v-model="form.endTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item style="margin-bottom:8px !important;" label="">
                <el-button type="primary" v-preventReClick="2000" @click="search">查询</el-button>
                <el-button v-preventReClick="2000" @click="reset">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
    <div class="box-table">
        <el-table height="100%" v-loading="loading" :data="tableData" tooltip-effect="dark">
            <template slot="empty">
                <no-data :types="isSearch">
                    <span>暂无数据</span>
                </no-data>
            </template>
            <el-table-column prop="experimentName" label="日志ID" show-overflow-tooltip></el-table-column>
            <el-table-column prop="createOper" label="任务名称" show-overflow-tooltip></el-table-column>
            <el-table-column prop="lastUpdateOper" label="提交人" show-overflow-tooltip></el-table-column>
            <el-table-column label="状态" show-overflow-tooltip>
                <template slot-scope="scope">{{scope.status}}</template>
            </el-table-column>
            <el-table-column sortable prop="createTime" label="计划执行时间" show-overflow-tooltip min-width="100"></el-table-column>
            <el-table-column sortable prop="lastUpdateTime" label="开始时间" show-overflow-tooltip min-width="100"></el-table-column>
            <el-table-column sortable prop="lastUpdateTime" label="结束时间" show-overflow-tooltip min-width="100"></el-table-column>
            <el-table-column sortable prop="lastUpdateTime" label="运行时长(s)" show-overflow-tooltip min-width="100"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button type="text" @click="handleToDetail(scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div v-if="tableData.length>0" class="box-pagenation">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</div>
</template>

<script>
import {
    mapGetters,
    mapMutations
} from 'vuex'
import NoData from '@/components/NoData'
export default {
    name: 'TaskLogs',
    components: {
        NoData
    },
    data () {
        return {
            loading: false,
            statusList: [
                { value: 0, label: '已调度' },
                { value: 1, label: '未调度' }
            ],
            form: {
                name: '',
                status: '',
                excuteTime: [],
                startTime: [],
                endTime: []
            },
            total: 0,
            pageSize: 10,
            currentPage: 1,
            tableData: [],
            isSearch: false
        }
    },
    created () {
        this.init()
    },
    computed: {
        ...mapGetters({
            projectId: 'common/getProjectId'
        })
    },
    methods: {
        ...mapMutations({
            setUpdateExp: 'common/setUpdateExp',
            setTypeId: 'common/setTypeId',
            setRemoveExp: 'common/setRemoveExp'
        }),
        search () {
            this.currentPage = 1
            this.isSearch = true
            this.init()
        },
        init () {
            this.loading = true
            const params = {
                projectId: this.projectId,
                keyword: this.keyword,
                pageSize: this.pageSize,
                pageNum: this.currentPage
            }
            this.$post('/experiment/queryExperiments', params).then(res => {
                if (res) {
                    const {
                        total,
                        rows
                    } = res
                    this.total = total
                    this.tableData = rows
                }
            }).finally(() => {
                this.loading = false
            })
        },
        reset () {
            this.keyword = ''
            this.isSearch = false
            this.currentPage = 1
            this.init()
        },
        handleToDetail (item) {
        },
        handleCurrentChange (val) {
            this.currentPage = val
            this.init()
        },
        handleSizeChange (val) {
            this.pageSize = val
            this.init()
        }
    }
}
</script>
<style lang="less">
    .task-logs {
        height: 100%;
        overflow: hidden;
        .box-table {
            height: calc(100% - 100px);
        }
    }
</style>
